package com.myway.ibe.command;

import com.google.common.base.Preconditions;
import com.myway.ibe.config.IBEClientConfig;
import com.travelsky.ibe.client.IBEClient;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;

/**
 * Created by Administrator on 2018/1/15.
 */
@Slf4j
public abstract class BaseIBECommand implements BaseCommand{
    private IBEClientConfig config;

    public IBEClientConfig getConfig() {
        return this.config;
    }

    public void setConfig(IBEClientConfig config) {
        this.config = config;
    }

    /**
     * 连接IBE服务器
     * 1233
     */
    public void configIBEClient(IBEClient client){
        Preconditions.checkNotNull(client,"No ibe instance to set params");
        client.setAgentInfo(config.getOffice(), config.getCustomno(), config.getValidationno());
        client.setAppName(config.getApp());
        String ipAddress=config.getIp();

        if(new Date().getTime()%2==0){
            ipAddress=config.getBackupIp();
        }
        log.info("use ip "+ipAddress+" to access travelsky ibe.");
        client.setConnectionInfo(ipAddress,Integer.parseInt(config.getPort()));
    }
    public String test(){
        return "success";
    }
}
